package com.imooc.service;

import com.imooc.dao.GirlDao;
import com.imooc.respository.GirlsRespository;
import com.imooc.domain.Girl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by ancy on 2017/7/8.
 */
@Service
public class GirlsService {

    @Autowired
    private GirlsRespository girlsRespository;

    @Autowired
    private GirlDao  girlDao;

    @Transactional
    public  void insertTwo () {

        Girl girl01 = new Girl();
        girl01.setName("A");
        girl01.setAge(23);
        girlsRespository.save(girl01);

        int i = 2/0;

        Girl girl02 = new Girl();
        girl02.setName("B");
        girl02.setAge(123);
        girlsRespository.save(girl02);
    }


    public  void  getAge (Integer id) throws Exception {
        Girl girl = girlsRespository.findOne(id);
        Integer age = girl.getAge();

        if (age < 10) {
            // 上小学

        }else if (age >=10 & age < 16) {
            // 上初中
        }
        // 如果 大于 16  加强
    }

    public  Girl queryGirlByName(String name) {
        return  girlDao.selectByName(name);
    }
}
